<template>
   <div>
     <div class="top">
            <van-nav-bar
            title="修改密码"
            left-text="返回"
            left-arrow
            class="header"
            @click-left="$router.back(-1)"
            />
        </div>
    <div class="modifymm">
        <form action="">
            <div class="oldpassword"><label>原始密码：</label><input type="password" placeholder="请输入原始密码"  v-model="ysmm"/></div>
            <div class="newpassword"><label>新设密码：</label><input type="password" placeholder="请输入新设密码" v-model="xmm" /></div>
            <div class="confirmpassword"><label>确认密码：</label><input type="password" placeholder="请再次输入新设密码" v-model="xamm" /></div>
            <button type="button" class="truemodify" @click="change()">确认修改</button>
        </form>
    </div>
   </div>
</template>

<script>
import axios from 'axios'
import { Toast, Uploader } from 'vant'
    export default {
        name: 'ModifymIndex',
        data(){
            return{
ysmm:'',
xmm:'',
xamm:'',
message:''
            }
        },
  methods:{

      change(){

var ysmm=this.ysmm;
var xmm=this.xmm;
var xamm=this.xamm;
 var userid=localStorage.getItem('userid');
        var token=localStorage.getItem('token');
        var that=this;
if(ysmm ==""){
  Toast('请输入原始密码')
  return;
}
else if(xmm ==""){
  Toast('请输入新密码')
  return;
}
else if(xamm ==""){
  Toast('请再次输入新设密码')
  return;
}
else if(xmm != xamm){
   Toast('俩次密码输入不一致')
  return;
}else{


  axios.post('/api/user/change-password',{
          oldpassword:ysmm,
           newpassword:xmm,
           confirmpassword:xamm
            },
            {
              headers: {
            'Authorization': 'Bearer ' + token
        }
            }
            )
          .then(response=>{
              console.log(response)
              var status =response.data.status;
              var message =response.data.message;
            this.message=message

              Toast({
                message:message
              })

              if(status == 0){
                setTimeout(function(){
                  that.$router.push({
                    path:'/login'
                  })
                },1500)
              }

          })
}



          }

    }

    }
</script>

<style lang="stylus" scoped>
.top >>> .header
    background: #259e7b
    color: #ffffff
.top >>> .van-nav-bar__text, .top >>> .van-icon-arrow::before
    color: #ffffff !important
.modifymm
    padding: 2rem
.modifymm >>> div
    margin: 2rem
    text-align: center
  label
    font-size:.8rem
  input
    padding: .2rem .5rem
.truemodify
    border-radius: .3rem
    margin: 5rem auto
    background: #259E7B
    display: -webkit-box
    display: -ms-flexbox
    display: flex
    border: 0
    padding: 0.5rem 6rem
    color: #fff
</style>
